package cn.itsource.wechat.controller;

import cn.itsource.basic.util.JsonResult;
import cn.itsource.org.pojo.Do.LoginDo;
import cn.itsource.org.service.IEmployeeService;
import cn.itsource.org.service.IUserService;
import cn.itsource.wechat.pojo.dto.BindDto;
import cn.itsource.wechat.pojo.info.WeChatProperties;
import cn.itsource.wechat.service.IWeChatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * department控制层
 */
@Controller
@Api(tags = "微信管理")
@RequestMapping("/wechat")
public class WeChatController {
    @Autowired
    private WeChatProperties weChatProperties;
    @Resource
    private IWeChatService weChatService;
    @GetMapping("/login")
    @ApiOperation(value = "微信登录",notes = "微信登录")
    public String userLogin(){
        //https://open.weixin.qq.com/connect/qrconnect?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_login&state=%s#wechat_redirect
        return weChatService.login();
    }
    @GetMapping("/callback")
    @ApiOperation(value = "回调",notes = "回调")
    public String callback(String code){
        //https://open.weixin.qq.com/connect/qrconnect?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_login&state=%s#wechat_redirect
        return weChatService.callback(code);
    }
    @PostMapping("/binder")
    @ApiOperation(value = "绑定",notes = "绑定")
    @ResponseBody
    public JsonResult binder(@RequestBody BindDto bindDto){

        return weChatService.binder(bindDto);
    }
    /**
     * employee登录
     */
    @GetMapping("/test")
    @ApiOperation(value = "测试")
    public void test() {

        System.out.println(weChatProperties);
        System.out.println(weChatProperties.getAppId());

        //WeChatProperties(tokenUrl=https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code, authorizationCodeUrl=https://open.weixin.qq.com/connect/qrconnect?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_login&state=%s#wechat_redirect, userinfoUrl=https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s, refreshTokenUrl=https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=%s&grant_type=refresh_token&refresh_token=%s, appId=wxd853562a0548a7d0, appSecrect=4a5d5615f93f24bdba2ba8534642dbb6, redirectUri=http://bugtracker.itsource.cn/wechat/callback)
    }
}





